#ifndef __IDevice_hpp__
#define __IDevice_hpp__

//#include "Device.hpp"
#include "Display.hpp"
#include "Window.hpp"
#include "Mouse.hpp"
#include "Keyboard.hpp"

namespace ge {

//----------------------------------------------------------------------------//
// IDevice
//----------------------------------------------------------------------------//

class IDevice : public Singleton< IDevice >
{
 public:

     // main

     static IDevice* CreateInstance( void ); 

     IDevice( void ) : m_refcnt( 0 )
     {
     }

     virtual void AddRef( void )
     {
          ++ m_refcnt;
     }

     virtual void Release( void )
     {
          if( !( -- m_refcnt ) ) delete this;
     }

     virtual void Process( int _action ) = 0;

     // display

     virtual void SetDisplayMode( uint _id ) = 0;

     virtual uint GetDisplayMode( void ) = 0;

     virtual const Display::Info& GetDisplayInfo( void ) = 0;

     virtual uint GetDefaultDisplayMode( void ) = 0;

     virtual uint GetCurrentDisplayMode( void ) = 0;

     // window

     typedef void ( * OnWindowActivatingPfn ) ( bool _activate );
     typedef void ( * OnWindowMovePfn ) ( int _x, int _y, Window::ShowType _show );
     typedef void ( * OnWindowResizePfn ) ( uint _width, uint _height, Window::ShowType _show );
     typedef void ( * OnWindowClosePfn ) ( void );

     virtual void SetWindowCallbacks( OnWindowActivatingPfn _activate_cb, OnWindowMovePfn _move_cb, OnWindowResizePfn _resize_cb, OnWindowClosePfn _close_cb ) = 0;

     virtual bool GetShow( void ) = 0;

     virtual void SetShow( bool _enabled = true ) = 0;
     
     virtual Window::ShowType GetShowType( void ) = 0;

     virtual Window::ShowType GetNormalShowType( void ) = 0;

     virtual void SetShowType( Window::ShowType _type ) = 0;

     virtual Size2ui GetSize( void ) = 0;

     virtual Size2ui GetNormalSize( void ) = 0;

     virtual void ResizeWindow( uint _width, uint _height ) = 0;

     virtual Point2i GetPos( void ) = 0;

     virtual Point2i GetNormalPos( void ) = 0;

     virtual void MoveWindow( int _x, int _y ) = 0;

     virtual bool GetResizable( void ) = 0;

     virtual void SetResizable( bool _enabled ) = 0;

     virtual bool GetFullscreen( void ) = 0;

     virtual void SetFullscreen( bool _enabled ) = 0;

     virtual String GetTitle( void ) = 0;

     virtual void SetTitle( const String& _title ) = 0;

     virtual bool IsActive( void ) = 0;

     // keyboard

     typedef void ( * OnKeyboardFocusPfn ) ( bool _focus );
     typedef void ( * OnKeyboardKeyPfn ) ( Keyboard::Key _key, int _action, char _ch );

     virtual void SetKeyboardCallbacks( OnKeyboardFocusPfn _focus_cb, OnKeyboardKeyPfn _key_cb ) = 0;

     virtual const uint* GetKeyboardState( void ) = 0;

     virtual uint32 GetCtrlKeysState( void ) = 0;

     virtual void ClearKeyboardEventQueue( void ) = 0;

     // mouse

     typedef void ( * OnMouseFocusPfn ) ( bool _focus );
     typedef void ( * OnMouseMovePfn ) ( int _x, int _y, bool _over_window );
     typedef void ( * OnMouseButtonPfn ) ( Mouse::Button _button, uint _action );
     typedef void ( * OnMouseWheelPfn ) ( int _z );

     virtual void SetMouseCallbacks( OnMouseFocusPfn _focus_cb, OnMouseMovePfn _move_cb, OnMouseButtonPfn _button_cb, OnMouseWheelPfn _wheel_cb ) = 0; 

     virtual uint32 GetMouseState( void ) = 0;

     virtual bool GetCursorClip( void ) = 0;

     virtual void SetCursorClip( bool _enabled ) = 0;

     virtual Point2i GetCursorPos( void ) = 0;

     virtual void SetCursorPos( int _x, int _y ) = 0;

     virtual bool GetShowCursor( void ) = 0;

     virtual void SetShowCursor( bool _enabled ) = 0;

     virtual void ClearMouseEventQueue( void ) = 0;

 protected:

     virtual ~IDevice( void )
     {
     }

     int m_refcnt;

 private:

     IDevice( const IDevice& );
     IDevice& operator = ( const IDevice& );
};

} // namespace ge

#endif//__IDevice_hpp__
